﻿$(document).ready(function() {

    $("#dThinking").hide();
    $("#ContactResponse").hide();
    $("input.PhoneMask").mask("(999) 999-9999");
    $("input.ZipCodeMask").mask("99999");
    $('.error').hide();

    //Default action and Initial Focus
    $('#FirstName').focus();
    //http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
    $("form input").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('button[type=submit] .default').click();
            return true;
        }
    });

    $("#ContactForm").validate({ submitHandler: function(form) {

        $("#dMakeContact").slideToggle(400);
        $("#dThinking").slideToggle(400);

        $(form).ajaxSubmit({ type: "POST",
            url: "ContactHandlerwEmail.ashx",
            success: function(result) {
            $("#dThinking").slideToggle(400);
                $("#dError").hide();
                $("#ContactResponse").slideToggle(400);
                if (result > 0) {
                } else {
                    $("#dError").show();
                    $("#tabs").show();
                }
            }
        });
        return false;
    }
    });

});
